class MarcaController < ApplicationController

  def index
    list
    
    render :action => 'list'
  end
  
  def edit
    @marca = Marca.find(params[:id])
    populate_collections
  end

  def list
    @marcas = Marca.paginate :page => params[:page], :per_page => DEFAULT_PER_PAGE, :order => 'nombre'
  end

  def show
  end

  def new
    populate_collections
    @marca = Marca.new
  end
  
  def populate_collections
    @categorias = Categoria.find(:all, :order => 'nombre')
    @familias = Familia.find(:all, :order => 'nombre')
    @empresas = Empresa.find(:all, :order => 'nombre')
  end
  
  def update
    @marca = Marca.find(params[:id])
    
    if @marca.update_attributes(params[:marca])
      flash[:notice] = "Actualizaci&oacute;n correcta"
      
      redirect_to :action => 'index'
    else
      populate_collections
      render :action => 'edit', :id => @marca
    end
  end
  
  def create
    @marca = Marca.new(params[:marca])
    
    if @marca.save
      flash[:notice] = "Se guardo nueva marca"
      
      redirect_to :action => "index"
    else
      populate_collections
      
      render :action => "new"
    end
  end
end
